
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using AOT;
using UnityEngine;

namespace CC_test {
    public class cppu3d {
#if UNITY_IPHONE
		const string dll_tag = "__Internal";
#else
        const string dll_tag = "cppu3d";
#endif
        [DllImport(dll_tag, CharSet = CharSet.Unicode)]
        public static extern int S_001(IntPtr pp, int ii);     
        //C#中结构体声明：    
        [StructLayout(LayoutKind.Sequential)]
        public struct GPlane {
            public double timestamp;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
            public float[] normal;                                                       
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
            public float[] center;
        }

        //C#中方法声明：
        [DllImport(dll_tag, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        private static extern bool Pvr_getAirGlassPlanes([In, Out] GPlane[] plane, int size);
                    
        //C#中调用该方法：
        public void S_mmmm() {
            int size = 2;    
            GPlane[] plane = new GPlane[size];    
            Pvr_getAirGlassPlanes(plane, size);
        }
    }
 
    public class cpp_log_output {
#if UNITY_IPHONE
		const string dll_tag = "__Internal";
#else
        const string dll_tag = "cpp002";
#endif
        //Unity中代码
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        public delegate void cpp_LogDelegate(int type, string tag, string currentTime, string message, string stackTrace);
        [DllImport(dll_tag, CallingConvention = CallingConvention.Cdecl)]
        public static extern void InitCSharpDelegate_log(cpp_LogDelegate log);
        [MonoPInvokeCallback(typeof(cpp_LogDelegate))]
        public static void cpp_Log(int type, string tag, string currentTime, string message, string stackTrace) {
            //C_LogCat.GetInstance().S_Log((byte)type, tag, currentTime, message, stackTrace);
            Debug.LogErrorFormat("接受cpp.消息..___" + message + "___" + stackTrace);
        }
        public static void S_RegisterDelegateToCpp() {
            try {
                InitCSharpDelegate_log(cpp_Log);
                Debug.LogFormat("设置成功.........InitCSharpDelegate_log02");
            } catch {
                Debug.LogErrorFormat("设置失败.........InitCSharpDelegate_log02");
            }
        }
    }
 

}
